package com.hkts.management.utils;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.json.JSONUtil;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtil {


    /**
     * 字符串转BigDecimal
     */
    public static BigDecimal getbd(String str){
        BigDecimal bd=new BigDecimal(str);
        return bd;
    }
    /**
     * 字符串转localdatetime
     */
    public static LocalDateTime getldt(String str){
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime time = LocalDateTime.now();
        String format = df.format(time);
        LocalDateTime parse = LocalDateTime.parse(str, df);
        return parse;
    }
    public static String spilt(String str) {
        StringBuffer sb = new StringBuffer();

        String[] temp = str.split(",");

        for (int i = 0; i < temp.length; i++) {
            if (!"".equals(temp[i]) && temp[i] != null)

                sb.append( temp[i] + "米,");

        }

        String result = sb.toString();

        String tp = result.substring(result.length() - 1, result.length());

        if (",".equals(tp))

            return result.substring(0, result.length() - 1);

        else

            return result;

    }
    public static String getRegionName(String[] str,Integer index) {
        Object[] any = ArrayUtil.getAny(str, index);
        String s = JSONUtil.toJsonStr(any);


        return s;
    }
    public static String  filtered(String str){
        String regEx="[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？]";
        Pattern p   =   Pattern.compile(regEx);
        Matcher m   =   p.matcher(str);
        return   m.replaceAll("").trim();
    }


}
